<?php
/**
 * Created by PhpStorm.
 * User: 王松
 * Time: 2018/5/25 15:41
 */

namespace App\Project\Traits\Model;

use Illuminate\Database\Eloquent\Builder;

trait DiabetesDiseaseStage
{
    /**
     * 糖尿病分期类型
     * @var array
     */
    public static $diabetes_stage_types = [];

    /**
     * @var array
     */
    public static $diabetes_stage_type_keys = [];

    public function scopeDiabetesStage(Builder $builder, $stage_flag)
    {
        if (!is_numeric($stage_flag)) {
            $stage_flag = array_search($stage_flag, static::$diabetes_stage_type_keys);
        }

        if ($stage_flag)
            $builder->where('diabetes_stage', $stage_flag);
    }

    public function stageOfCn()
    {
        return static::$diabetes_stage_types[$this->diabetes_stage];
    }

    public function stageOfEn()
    {
        return static::$diabetes_stage_type_keys[$this->diabetes_stage];
    }
}